home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
escalant
/
escala21.lha
/
escalante2.1
/
src
/
gfx
/
Gfx.h
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-15
|
12KB
|
541 lines
//
// Copyright (C) 1993 Jeff McWhirter
//
#ifndef GFX_H
#define GFX_H
#include "EscalanteGlobal.h"
#include "Rectangle.h"
#include "Set.h"
#include "CommonGfx.h"
#include "PointArray.h"
#include "Line.h"
#include "Oval.h"
#include "Geometry.h"
#include "VGraphElement.h"
class Ink* GetGrey(float);
char* GetBitmapPath(char * name);
class Bitmap;
extern Bitmap* MakeBitmap(char*);
extern Bitmap* FindBitmap(char *);
extern void MakeColorList();
inline bool OkToDrawText(){return (GrGetXScale() >=0.6);}
enum GfxFlags{
eGfxBatching = BIT(eGOLast+1),
eGfxShown = BIT(eGOLast+2),
eGfxDying = BIT(eGOLast+3),
eGfxInCalcImage = BIT(eGOLast+4),
eGfxFilled = BIT(eGOLast+5),
eGfxAttachable = BIT(eGOLast+6),
eGfxGuard = BIT(eGOLast+7),
eGfxPickable = BIT(eGOLast+8),
eGfxPropChanges = BIT(eGOLast+9),
eGfxDrawOutline = BIT(eGOLast+10),
eGfxInput = BIT(eGOLast+11),
eGfxMapW = BIT(eGOLast+12),
eGfxMapH = BIT(eGOLast+13),
eGfxMapA = BIT(eGOLast+14),
eGfxLast = eGOLast +14
};
inline ESCALANTEColor PercentToGrey(float perc){
if(perc < 0.05) perc = 0.05;
if(perc > 1.0) perc = 1.0;
ESCALANTEColor c;
c = (ESCALANTEColor)((int)eGrey05 + (int)(perc*100.0/2.5 + 0.5)) ;
if(c < eGrey05)c = eGrey05;
else if(c > eGrey100)c = eGrey100;
return c;
}
class GfxState : public Object{
public:
int svpensize;
Point svtextpos;
Ink* svpenink;
Ink* svfillink;
Ink* svtextink;
Font* svtextfont;
int penwidth;
ESCALANTEColor pencolor;
ESCALANTEColor fillcolor;
ESCALANTEFace textface;
Ink* fgrey;
Ink* pgrey;
int textsize;
ESCALANTEColor textcolor;
ESCALANTEFont textfont;
MetaDef(GfxState)
GfxState();
virtual void Setup();
virtual void SaveState();
virtual void RestoreState();
OStream& PrintOn(OStream& o);
IStream& ReadFrom(IStream& i );
};
#define Gfx_BASE GraphObject
class Gfx: public GraphObject{
public:
int gfx_id;
GfxState* gfxstate;
class Gfx* parent;
Rectangle ibbox;
VGraphElement* elt;
MetaDef(Gfx)
Gfx(VGraphElement * elt= 0);
~Gfx();
void InitClone();
bool GfxOK(int mask);
int GetId(){return gfx_id;}
void SetId(int i){gfx_id = i; Gfx_BASE::SetId(gfx_id);}
virtual void MakeGfxState(){gfxstate = new GfxState();}
inline void CheckGfxState(){if(!gfxstate)MakeGfxState();}
virtual void * GetShape(){
if(DrawOutline()) return (void*)&ibbox;
else return 0;
}
virtual ShapeType GetShapeType(){
if(DrawOutline()) return eRectangle;
else return eNullShape;
}
virtual void MoveBy(Point&);
virtual void SetDelta(Point &){}
virtual bool MyImageTouchesPoint(Point& );
virtual bool MyImageTouchesRect(Rectangle& );
bool PropagateChanges(){
return (!TestFlag(eGfxPropChanges)?FALSE:
(parent?parent->PropagateChanges():TRUE));
}
void PropagateChanges(bool f){ SetFlag(eGfxPropChanges,f);}
Gfx * GetClosestGfx(Gfx * ogfx,
Point * myp=0,
Point * op=0,
Gfx ** minogfx = 0,
int flags = eGfxShown,
int * currentmin = 0 );
Gfx * GetClosestGfx(void * g,
ShapeType type,
Point * gp=0,
Point * op=0,
int flags = eGfxShown,
int * currentmin = 0 );
virtual Gfx * GetClosestGfx2(Gfx * ogfx,
Point * myp=0,
Point * op=0,
Gfx ** minogfx = 0,
int flags = eGfxShown,
int * currentmin = 0 );
virtual Gfx * GetClosestGfx2(void * g,
ShapeType type,
Point * gp=0,
Point * op=0,
int flags = eGfxShown,
int * currentmin = 0 );
inline Gfx* GetClosestGfx(Point &p,Point* gp=0,int flags = eGfxShown, int* currentmin =0 )
{
return GetClosestGfx((void*)&p, ePoint, gp, 0,flags,currentmin);
}
inline Gfx* GetClosestGfx(Line& p, Point* gp=0, Point*op=0,int flags = eGfxShown, int* currentmin =0 )
{
return GetClosestGfx((void*)&p, eLine, gp, op, flags,currentmin);
}
inline Gfx* GetClosestGfx(Rectangle &p, Point* gp=0, Point*op=0, int flags = eGfxShown, int* currentmin =0 )
{
return GetClosestGfx((void*)&p, eRectangle, gp, op, flags,currentmin);
}
inline Gfx* GetClosestGfx(Oval &p, Point* gp=0, Point*op=0, int flags = eGfxShown, int* currentmin =0 )
{
return GetClosestGfx((void*)&p, eOval, gp, op, flags,currentmin);
}
inline Gfx* GetClosestGfx(PointArray & p, Point* gp=0, Point*op=0, int flags = eGfxShown, int*currentmin =0 )
{
return GetClosestGfx((void*)&p, ePointArray, gp, op, flags,currentmin);
}
virtual int DistanceTo(Point &);
virtual int DistanceTo(Line &);
virtual int DistanceTo(Rectangle & );
virtual int DistanceTo(PointArray&);
virtual int DistanceTo(Oval & r );
Point ClosestPoint(void* g, ShapeType t,Point* op =0,bool attach = FALSE);
virtual Point ClosestPoint(Point &,bool attach = FALSE);
virtual Point ClosestPoint(Line & ,Point*op = 0 );
virtual Point ClosestPoint(Rectangle &,Point*op = 0 );
virtual Point ClosestPoint(Oval &,Point*op = 0 );
virtual Point ClosestPoint( PointArray &,Point*op = 0 );
virtual void GetAllGfxWithId(int i,Set & s);
virtual Gfx* GetGfx(Class* c = 0, int id = -1,int flags = 0);
virtual Gfx* GetGfxOnPt(Point p, Class* c = 0, int id = -1,int flags = eGfxShown);
virtual Gfx* GetGfxOnRect(Rectangle r, Class* c = 0 , int id = -1,int flags = eGfxShown);
Gfx* GetGfxWithId(int i,int flags = 0){return GetGfx(0,i,flags);}
Gfx* GetGfxWithIdOnPt(int i,Point p,int flags = eGfxShown){return GetGfxOnPt(p,0,i,flags);}
Gfx* GetGfxWithIdOnRect(int i,Rectangle r,int flags = eGfxShown){return GetGfxOnRect(r,0,i,flags);}
Gfx* GetGfxOfClass(Class* c,int flags = eGfxShown) {return GetGfx(c,-1,flags);}
Gfx* GetGfxOfClassOnPt( Class* c,Point p,int flags = eGfxShown){return GetGfxOnPt(p,c,-1,flags);}
Gfx* GetGfxOfClassOnRect( Class* c, Rectangle r,int flags = eGfxShown) {return GetGfxOnRect(r,c,-1,flags);}
Font* GetFont(){
if(!HaveFontDefined()) return gSysFont;
return new_Font(GetTextFont(),GetTextSize(), GetTextFace());
}
inline void SetBatch(bool b){
if(b == TestFlag(eGfxBatching)) return;
SetFlag(eGfxBatching,b);
if(!b) CalcImageBBox();
}
inline bool Batching(){return (TestFlag(eGfxBatching) ? TRUE: (parent ? parent->Batching():FALSE));}
void Init();
void SetElement(VGraphElement* g=0) {
BEGINGUARD(eGfxGuard)
SetElement2(g);
ENDGUARD(eGfxGuard)
}
virtual void SetElement2(VGraphElement* g=0) { elt = g;}
inline VGraphElement* GetElement() {return (elt? elt : (parent? parent->GetElement(): 0));}
inline void SetParent(Gfx* p=0) { parent = p; SignalNewFont();}
inline Gfx* GetParent() {return parent;}
virtual void ToFront(Gfx* g = 0);
virtual void ToBack(Gfx* g = 0);
void* GetAttribute(int aid, DataType & type);
void ChangeAttribute(int aid, void* data, DataType type);
AttrMap* MapAttribute(int external, int internal, Object* fromobj, AttrFilter* af=0);
virtual bool GetLocPt(LocPt lp , Point* p,void* data =0 );
inline void SetFilled(bool f){SetFlag(eGfxFilled,f);SignalChange(ibbox);}
inline bool GetFilled(){return (TestFlag(eGfxFilled));}
inline bool Attachable(){
return (TestFlag(eGfxAttachable) && (parent ? parent->Attachable():TRUE));
}
inline void SetAttachable(bool s){ SetFlag(eGfxAttachable,s);}
inline bool Pickable()
{
return (TestFlag(eGfxPickable) && (parent ? parent->Pickable():TRUE));
}
inline void SetPickable(bool s){
SetFlag(eGfxPickable,s);
}
inline Gfx* GetRoot(){return (parent?parent->GetRoot():this);}
inline bool CanShow(){
return (
((elt && ! elt->GetVisible()) ? FALSE:
(TestFlag(eGfxShown) && (parent ? parent->CanShow(): TRUE)))
);
}
inline void SetShown(bool s){
if(s != TestFlag(eGfxShown)){
SetFlag(eGfxShown,s);
SignalChange(ibbox);
ibbox = gRect0;
CalcImageBBox();
}
}
//Graphics state functions
inline bool HaveFillColor(){return (gfxstate && (gfxstate->fillcolor != eNullColor));}
inline bool HavePenColor(){return (gfxstate && (gfxstate->pencolor != eNullColor));}
inline bool HavePenSize(){return (gfxstate && (gfxstate->penwidth != NULLSIZE));}
inline bool HaveTextFace(){return (gfxstate && (gfxstate->textface != NULLTEXTFACE));}
inline bool HaveTextSize(){return (gfxstate && (gfxstate->textsize != NULLTEXTSIZE));}
inline bool HaveTextColor(){return (gfxstate && (gfxstate->textcolor != eNullColor));}
inline bool HaveTextFont(){return (gfxstate && (gfxstate->textfont != NULLTEXTFONT));}
inline void SetFillColor (ESCALANTEColor fc = eNullColor) {
if(fc <0 || fc > (int)eLastColor) return;
CheckGfxState();
if(gfxstate->fillcolor == fc) return;
gfxstate->fillcolor = fc;
gfxstate->fgrey =0;
SignalChange(ibbox);
}
inline void SetFillColor (float perc){
CheckGfxState();
gfxstate->fgrey = GetGrey(perc);
// gfxstate->fillcolor = PercentToGrey(perc);
SignalChange(ibbox);
}
inline ESCALANTEColor GetFillColor(){
return
(HaveFillColor() ? gfxstate->fillcolor:
(parent? parent->GetFillColor() :(ESCALANTEColor)e_ePatNone));
}
inline ESCALANTEColor GetPenColor(){return (HavePenColor() ? gfxstate->pencolor:
(parent? parent->GetPenColor() :(ESCALANTEColor)DefaultColor));}
inline void SetPenColor(ESCALANTEColor pc = eNullColor) {
if(pc <0 || pc > (int)eLastColor) return;
CheckGfxState();
if(gfxstate->pencolor == pc) return;
gfxstate->pencolor = pc;
gfxstate->fgrey = 0;
SignalChange(ibbox);
}
inline void SetPenColor (float perc){
CheckGfxState();
gfxstate->pgrey = GetGrey(perc);
// gfxstate->pencolor = PercentToGrey(perc);
SignalChange(ibbox);
}
inline int GetPenSize(){return (HavePenSize() ? gfxstate->penwidth:
(parent? parent->GetPenSize() :DefaultSize));}
inline void SetPenSize(int pw = NULLSIZE) {
CheckGfxState();
if(gfxstate->penwidth == pw) return;
gfxstate->penwidth = pw;
CalcImageBBox();
}
virtual void SignalNewFont(){}
inline void SetTextFace(ESCALANTEFace f) {
CheckGfxState();
if(gfxstate->textface == f) return;
gfxstate->textface = f;
SignalNewFont();
SignalChange(ibbox);
}
inline ESCALANTEFace GetTextFace() {
return (HaveTextFace() ? gfxstate-> textface:
(parent ? parent->GetTextFace ():(ESCALANTEFace) DFLTFACE));
}
inline void SetTextSize(int s ) {
CheckGfxState();
if(gfxstate->textsize == s) return;
gfxstate->textsize = s;
SignalNewFont();
CalcImageBBox();
}
inline int GetTextSize() {
return (HaveTextSize() ? gfxstate->textsize:
(parent ? parent->GetTextSize (): DFLTSIZE) );
}
inline void SetTextColor(ESCALANTEColor c ) {
if(c <0 || c > (int)eLastColor) return;
CheckGfxState();
if(gfxstate->textcolor == c) return;
gfxstate->textcolor = c;
SignalChange(ibbox);
}
inline void SetTextColor (float perc){
CheckGfxState();
gfxstate->textcolor = PercentToGrey(perc);
SignalChange(ibbox);
}
inline ESCALANTEColor GetTextColor() {
return (HaveTextColor() ? gfxstate->textcolor:
(parent ? parent->GetTextColor() : (ESCALANTEColor)DefaultColor));
}
inline void SetTextFont(ESCALANTEFont f ) {
CheckGfxState();
if(gfxstate->textfont == f) return;
gfxstate->textfont = f;
SignalNewFont();
CalcImageBBox();
}
bool HaveFontDefined(){
if(HaveTextFont()) return TRUE;
if(parent) return parent->HaveFontDefined();
return FALSE;
}
inline ESCALANTEFont GetTextFont() {
return (HaveTextFont() ? gfxstate->textfont:
(parent ? parent->GetTextFont (): (ESCALANTEFont)DFLTFONT) );
}
void SignalChange(Rectangle r );
Rectangle AdjustRectangle(Rectangle r);
Rectangle CalcImageBBox();
Rectangle ResetImageBBox();
virtual Rectangle ResetImageBBox2(){return CalcImageBBox();}
virtual Rectangle CalcImageBBox2();
inline Rectangle GetImageBBox(){return ibbox;}
Point GetPointOfElt(LocPt lp);
void DrawInit(Rectangle r= gRect0, void* v =0);
virtual void Draw(Rectangle r,class View* v);
bool DrawOutline(){return TestFlag(eGfxDrawOutline);}
virtual void DrawOutline(bool b){
if(b == TestFlag(eGfxDrawOutline)) return;
SetFlag(eGfxDrawOutline,b);
SignalChange(ibbox);
CalcImageBBox();
}
virtual void Setup();
OStream& PrintOn(OStream& o);
IStream& ReadFrom(IStream& i );
};
#endif GFX_H